import requestnet from 'requestnet.js'
import api from 'api.js'
/**
 * 统一请求封装类
 */
class request {
  constructor() {
    this._request = new requestnet
    this._request.setErrorHandler(this.errorHander)
  }
  /**
     * 统一的异常处理方法
     */
  errorHander(res) {
    console.error(res)
  }

  /**
   * 获取token
   */
  getReq(url, params = {}) {
    return this._request.sendGetRequest(api.Base + url, params).then(res => res.data)
  }

  /**
   * post请求 传人接口的尾缀和form表单
   * 接受返回的res.data
   */
  postForm(url, params = {}) {
    return this._request.sendPostFormRequest(api.Base + url, params).then(res => res.data)
  }
  
    /**
   * post请求 传人接口的尾缀和form表单
   * 接受返回的res.data
   */
  postHeadForm(url, params = {}) {
    return this._request.postTokenFormRequest(api.Base + url, params).then(res => res.data)
  }
  

  /**
   * post请求 传人接口的尾缀和form表单
   * 接受返回的res.data
   */
  postJson(url, params = {}) {
    return this._request.sendPostJsonRequest(api.Base + url, params).then(res => res.data)
  }

  postHeadJson(url, params = {}){
    return this._request.postTokenJsonRequest(api.Base + url, params).then(res => res.data)
  }

}

export default request //class提供出去